package com.lemon.message.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import com.lemon.common.log.annotation.Log;
import com.lemon.common.log.enums.BusinessType;
import com.lemon.common.security.annotation.RequiresPermissions;
import com.lemon.message.domain.BiEmailTemplate;
import com.lemon.message.service.IBiEmailTemplateService;
import com.lemon.common.core.web.controller.BaseController;
import com.lemon.common.core.web.domain.AjaxResult;
import com.lemon.common.core.utils.poi.ExcelUtil;
import com.lemon.common.core.web.page.TableDataInfo;

/**
 * 包名称：com.lemon.message.controller
 * 类名称：BiEmailTemplateController
 * 类描述：邮件模板Controller
 * 创建人：@author lemon
 * 创建时间：2023-11-18
 */
@Api("邮件模板")
@RestController
@RequestMapping("/emailTemplate")
public class BiEmailTemplateController extends BaseController {

    @Autowired
    private IBiEmailTemplateService biEmailTemplateService;

    /**
     * 查询邮件模板列表
     * @Title: list
     * @Description: 查询邮件模板列表
     * @param biEmailTemplate 邮件模板
     * @return: TableDataInfo
     * @throws:
     * @author: lemon
     * @Date: 2023-11-18
     */
    @RequiresPermissions("message:emailTemplate:list")
    @GetMapping("/list")
    public TableDataInfo list(BiEmailTemplate biEmailTemplate) {
        startPage();
        List<BiEmailTemplate> list = biEmailTemplateService.selectBiEmailTemplateList(biEmailTemplate);
        return getDataTable(list);
    }

    /**
     * 导出邮件模板列表
     * @Title: export
     * @Description: 导出邮件模板列表
     * @param response 客户端响应对象
     * @param biEmailTemplate 邮件模板
     * @return:
     * @throws:
     * @author: lemon
     * @Date: 2023-11-18
     */
    @RequiresPermissions("message:emailTemplate:export")
    @Log(title = "邮件模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BiEmailTemplate biEmailTemplate) {
        List<BiEmailTemplate> list = biEmailTemplateService.selectBiEmailTemplateList(biEmailTemplate);
        ExcelUtil<BiEmailTemplate> util = new ExcelUtil<BiEmailTemplate>(BiEmailTemplate.class);
        util.exportExcel(response, list, "邮件模板数据");
    }

    /**
     * 获取邮件模板详细信息
     * @Title: getInfo
     * @Description: 获取邮件模板详细信息
     * @param id 邮件模板主键
     * @return: AjaxResult
     * @throws:
     * @author: lemon
     * @Date: 2023-11-18
     */
    @RequiresPermissions("message:emailTemplate:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(biEmailTemplateService.selectByPrimaryKey(id));
    }

    /**
     * 新增邮件模板
     * @Title: add
     * @Description: 新增邮件模板
     * @param biEmailTemplate 邮件模板
     * @return: AjaxResult
     * @throws:
     * @author: lemon
     * @Date: 2023-11-18
     */
    @RequiresPermissions("message:emailTemplate:add")
    @Log(title = "邮件模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BiEmailTemplate biEmailTemplate) {
        return toAjax(biEmailTemplateService.insert(biEmailTemplate));
    }

    /**
     * 修改邮件模板
     * @Title: edit
     * @Description: 修改邮件模板
     * @param biEmailTemplate 邮件模板
     * @return: AjaxResult
     * @throws:
     * @author: lemon
     * @Date: 2023-11-18
     */
    @RequiresPermissions("message:emailTemplate:edit")
    @Log(title = "邮件模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BiEmailTemplate biEmailTemplate) {
        return toAjax(biEmailTemplateService.update(biEmailTemplate));
    }

    /**
     * 删除邮件模板
     * @Title: remove
     * @Description: 删除邮件模板
     * @param ids 需要删除的邮件模板主键集合
     * @return: AjaxResult
     * @throws:
     * @author: lemon
     * @Date: 2023-11-18
     */
    @RequiresPermissions("message:emailTemplate:remove")
    @Log(title = "邮件模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(biEmailTemplateService.deleteByBatch(ids));
    }
}
